<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>癫痫病医疗管理系统</title>
  <!--引入layui.css文件-->
  <link rel="stylesheet" href="layui/css/layui.css" media="all">
  <link rel="stylesheet" href="layui/layuiAdmin/css/admin.css" media="all">
  <link rel="stylesheet" href="layui/layuiAdmin/css/login.css" media="all">
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <style>
    .layui-input1 {
      height: 30px;
      width: 140px;
      margin-left: 40px;
      line-height: 30px;
      border: 1px solid #ddd;
      border-radius: 4px;
      padding: 0 10px;
      font-size: 14px;
      color: #333;
      background-color: #fff;
      transition: all 0.3s;
    }

    .layui-input1:focus {
      border-color: #009688;
      box-shadow: 0 0 5px rgba(0, 150, 136, 0.5);
    }
  </style>
</head>
<body>

<!--登录框布局-->
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none ;background: linear-gradient(45deg, #2fdae3, #99ead0);">
  <div class="layadmin-user-login-main" style="background-color:white;border-radius: 5px;margin-top: 10%">
    <div class="layadmin-user-login-box layadmin-user-login-header">
      <h2>癫痫病医疗后台管理端</h2>
    </div>
    <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
        <input type="text" name="username" id="LAY-user-login-username" lay-verify="required|username" placeholder="用户名" value="admin" class="layui-input">
      </div>
      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
        <input type="password" name="password" id="LAY-user-login-password" lay-verify="required|password" placeholder="密码" value="123456" class="layui-input">
      </div>
      <div class="layui-form-item">
        <div class="layui-row">
          <div class="layui-col-xs7">
            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-vercode"></label>
            <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required|vercode" placeholder="图形验证码" value="" class="layui-input1">
          </div>
          <div class="layui-col-xs5">
            <div style="margin-left: 10px;">
              <canvas id="canvas" width="100" height="43"></canvas>
            </div>
          </div>
        </div>
      </div>
      <div class="layui-form-item" style="margin-bottom: 20px;">
        <input type="checkbox" name="remember" lay-skin="primary" title="记住密码">
        <a href="views/user/forget.html" class="layadmin-user-jump-change layadmin-link" style="margin-top: 7px;">忘记密码？</a>
      </div>
      <div class="layui-form-item">
        <button style="background: linear-gradient(45deg, #2f6de3, #63d2f5); border-color: #63d2f5; color: white" class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登  录</button>
      </div>
    </div>
  </div>

  <div class="layui-trans layadmin-user-login-footer">

    <p>© 2024 <a href="https://www.toutiao.com/c/user/token/MS4wLjABAAAACw3vTbcuPpd0e_JVMny9jAMGHyl-vVWV5y4IIMyLyKA/" target="_blank">gxa.com</a></p>
  </div>

</div>





<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<!--引入layui.js文件-->
<script src="layui/layui.js"></script>
<script>

    layui.config({
        base: 'layui/layuiAdmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','layer','form'], function(){
        var $ = layui.$
            ,setter = layui.setter
            ,layer = layui.layer
            ,admin = layui.admin
            ,form = layui.form
            ,router = layui.router()
            ,search = router.search;


        // form.render();
        //提交

      $(function(){
        var show_num = [];
        draw(show_num);

        $("#canvas").on('click',function(){
          draw(show_num);
        })

        form.on('submit(LAY-user-login-submit)', function(obj){
          var val = $(".layui-input1").val().toLowerCase();
          var username = $(".LAY-user-login-username").val();
          var password=$(".LAY-user-login-password").val();
          var remember = obj.field.remember;
          var num = show_num.join("");
          if(val==''){
            alert('请输入验证码！');
          }else if(val == num){
            if(remember) {
              localStorage.setItem('username', username);
              localStorage.setItem('password', password);
            } else {
              // 否则，清除LocalStorage中的用户名和密码
              localStorage.removeItem('username');
              localStorage.removeItem('password');
            }
            // 通过ajax调用后端登录接口，实现登录功能。
            $.ajax({
              url:"http://localhost:8888/login", //后端接口
              type:"get", //提交参数方式get|post
              data:obj.field, //提交参数
              dataType:"json", //后端返回的参数类型：json、html、text......
              success:function (res){ //成功后的回调函数 res = RespResult
                if(res.code == 0){
                  // 将该用户的登录信息，存放到localStorage对象中
                  localStorage.setItem("sysUserInfo",JSON.stringify(res.data))
                  //登入成功的提示与跳转
                  layer.msg(res.message, {
                    offset: '15px'
                    ,icon: 1
                    ,time: 1000
                  }, function(){
                    location.href = 'views/index.html'; //后台主页
                  });
                }else{
                  //错误提示
                  layer.msg(res.message, {
                    offset: '15px'
                    ,icon: 5
                    ,time: 2000
                  });
                }
              }
            })
            $(".input-val").val('');
            draw(show_num);

          }else{
            alert('验证码错误！请重新输入！');
            $(".input-val").val('');
            draw(show_num);
          }
        });
        var storedUsername = localStorage.getItem('username');
        var storedPassword = localStorage.getItem('password');
        if(storedUsername && storedPassword) {
          $('input[name="username"]').val(storedUsername);
          $('input[name="password"]').val(storedPassword);
          $('input[name="remember"]').prop('checked', true);
          form.render(); //更新渲染
        }
      })

    });
    $(function(){
      var show_num = [];
      draw(show_num);

      $("#canvas").on('click',function(){
        draw(show_num);
      })
      $(".btn").on('click',function(){
        var val = $(".input-val").val().toLowerCase();
        var num = show_num.join("");
        if(val==''){
          alert('请输入验证码！');
        }else if(val == num){
          alert('提交成功！');
          $(".input-val").val('');
          draw(show_num);

        }else{
          alert('验证码错误！请重新输入！');
          $(".input-val").val('');
          draw(show_num);
        }
      })
    })

    function draw(show_num) {
      var canvas_width=$('#canvas').width();
      var canvas_height=$('#canvas').height();
      var canvas = document.getElementById("canvas");//获取到canvas的对象，演员
      var context = canvas.getContext("2d");//获取到canvas画图的环境，演员表演的舞台
      canvas.width = canvas_width;
      canvas.height = canvas_height;
      var sCode = "A,B,C,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,W,X,Y,Z,1,2,3,4,5,6,7,8,9,0";
      var aCode = sCode.split(",");
      var aLength = aCode.length;//获取到数组的长度

      for (var i = 0; i <= 3; i++) {
        var j = Math.floor(Math.random() * aLength);//获取到随机的索引值
        var deg = Math.random() * 30 * Math.PI / 180;//产生0~30之间的随机弧度
        var txt = aCode[j];//得到随机的一个内容
        show_num[i] = txt.toLowerCase();
        var x = 10 + i * 20;//文字在canvas上的x坐标
        var y = 20 + Math.random() * 8;//文字在canvas上的y坐标
        context.font = "bold 23px 微软雅黑";

        context.translate(x, y);
        context.rotate(deg);

        context.fillStyle = randomColor();
        context.fillText(txt, 0, 0);

        context.rotate(-deg);
        context.translate(-x, -y);
      }
      for (var i = 0; i <= 5; i++) { //验证码上显示线条
        context.strokeStyle = randomColor();
        context.beginPath();
        context.moveTo(Math.random() * canvas_width, Math.random() * canvas_height);
        context.lineTo(Math.random() * canvas_width, Math.random() * canvas_height);
        context.stroke();
      }
      for (var i = 0; i <= 30; i++) { //验证码上显示小点
        context.strokeStyle = randomColor();
        context.beginPath();
        var x = Math.random() * canvas_width;
        var y = Math.random() * canvas_height;
        context.moveTo(x, y);
        context.lineTo(x + 1, y + 1);
        context.stroke();
      }
    }

    function randomColor() {//得到随机的颜色值
      var r = Math.floor(Math.random() * 256);
      var g = Math.floor(Math.random() * 256);
      var b = Math.floor(Math.random() * 256);
      return "rgb(" + r + "," + g + "," + b + ")";
    }


</script>
</body>
</html>